    $(function () {
        var myCar = $(".myCar");
        var obj = {
            count: 0
        };

        // 获取每条cookie数据
        if (document.cookie) {
            var template = "";

            var arr1 = document.cookie.split("=");
            if (arr1[0] == "shop") {
                arr1 = JSON.parse(arr1[1]);
                for (var i = 0; i < arr1.length; i++) {
                    var proId = arr1[i].id;
                    var type = arr1[i].type;
                    var color = arr1[i].color;
                    var num = parseInt(arr1[i].num);
                    var ind = i;
                    $.ajax({
                        type: "get",
                        async: false,
                        url: "../lib/product_detail01.php?id=" + proId,
                        dataType: "json",
                        success: function (response) {
                            response.forEach((elm, i) => {
                                var pic = JSON.parse(elm.pic);
                                template = `<div class="shopCar-main">
                                            <input type="checkbox" name="ckb" class="ckb">
                                            <a href="#" id="picA"><img src="..${pic.src}" alt="${pic.title}"></a>
                                            <a href="#" id="detailA"><span id="tit">${elm.title}</span><span id="det">${type}${color}</span></a>
                                            <span class="pre-price">￥${elm.price}</span>
                                            <div class="numBtn">
                                                <a href="#" class="reduce">-</a><a class="n"><input type="text" name="num" id="num" value="${num}"></a><a href="#"
                                                    class="add">+</a>
                                            </div>
                                            <span class="all-price">￥${(num* elm.price).toFixed(2)}</span>
                                            <a class="delThis">删除</a>
                                        </div>`;

                                obj.count = obj.count + 1;
                                myCar.append(template);
                                $(".allPrice").html(function (index, html) {
                                    return Number(html) + Number(num * elm.price);
                                });

                            })
                            // 购物车商品数量
                            $("#n1").html(obj.count);
                            var flag = 0,
                                a = 0;
                            $(".shopCar").on("click", "input", function () {

                                // 选中商品的数量，及删除选中商品
                                if ($(this).hasClass("ckb")) {
                                    if ($(this).is(":checked")) {
                                        flag++;
                                    } else {
                                        flag--;
                                    }
                                    $("#n2").html(flag);
                                    // 删除选中的商品
                                    $("#delSome").on("click", function () {
                                        var somePro = $("input").filter(function () {
                                            return $(this).is(":checked");
                                        });
                                        somePro.parent().remove();
                                    })
                                }
                                // 全选按钮
                                else if ($(this).hasClass("ckbAll")) {
                                    a++;
                                    // console.log(11);
                                    var ck = $("input").filter(function () {
                                        return $(this).hasClass("ckb");
                                    })
                                    if (a % 2) {
                                        ck.attr("checked", true);
                                        $("#n2").html(arr1.length);
                                    } else {
                                        ck.attr("checked", false);
                                        $("#n2").html(0);
                                    }
                                }

                            })

                        }
                    });
                }
            }
        }

        // 增加或减少商品数量
        myCar.on("click", "a", function () {
            event.preventDefault();
            if ($(this).hasClass("add")) {
                var val = $(this).prev().children();
                val.val(function () {
                    return Number(this.value) + 1;
                });
            } else if ($(this).hasClass("reduce")) {
                var val = $(this).next().children();
                val.val(function () {
                    if (this.value == 1) {
                        return 1;
                    } else {
                        return Number(this.value) - 1;
                    }
                });
            } else if ($(this).hasClass("delThis")) {
                console.log($(this).parent())
                $(this).parent().remove();
            }
        })

    })